package setvice;
import Dao.MemberDao;
import entity.Member;
import entity.User;
import setvice.MemberService;
import java.util.List;
import Dao.MemberDaoimpl;

import javax.swing.*;

public class MemberServiceimpl implements MemberService {
    MemberDao memberDao = new MemberDaoimpl();

    /*
    办理会员操作
     */
    @Override
    public boolean insertMemberService(Member member) {
        memberDao.insertMember(member);
        System.out.println("添加成功!");
        return true;
    }
    /*
        删除会员权益操作
         */
    @Override
    public boolean deleteMemberByVideomemberService(Integer id, String Videomember) {
        List<Member> memberList=memberDao.seekMemberById(id);
        if(memberList!=null){
            memberDao.deleteMemberByVideomember(id,Videomember);
            System.out.println("删除成功!");
            return true;
        }
        else{
            System.out.println("该会员不存在,删除失败!");
            return false;
        }
    }
    /*
    根据id,更改会员权益
     */
    @Override
    public boolean changeMemberByIdService(Integer id, String Videomember, Member member) {
        List<Member> memberList=memberDao.seekMemberById(id);
        if(memberList!=null){
            for(int i=0;i<memberList.size();i++){
                Member member1=memberList.get(i);
                if(member1.getVideomember().equals(Videomember)){
                    memberDao.changeMemberById(id,Videomember,member);
                    System.out.println("更改成功!");
                }
            }
            return true;
        }
        else{
            System.out.println("此会员权益不存在,根据此会员权益更改会员权益失败!");
            return false;
        }
    }
    /*
    查询所有用户的会员权益
     */
    @Override
    public List<Member> seekAllMemberService() {
        List<Member> memberList=memberDao.seekAllMember();
        if(memberList!=null){
            return memberList;
        }
        else {
            System.out.println("没有此用户!");
            return null;
        }
    }
    /*
    查询用户会员权益
     */
    @Override
    public List<Member> seekMemberByIdService(Integer id) {
        List<Member> memberList=memberDao.seekMemberById(id);
        if(memberList!=null){
            return memberList;
        }
        else {
            System.out.println("用户会员权益不存在!");
            return null;
        }
    }

}
